package com.example.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.demo.entity.Paper;
import com.example.demo.mapper.PaperMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PaperService {
    @Autowired
    private PaperMapper mapper;

    public List<Paper> get(String subject){
        QueryWrapper queryWrapper = new QueryWrapper<Paper>();
        if(subject == ""){
            return mapper.selectList(queryWrapper);
        }
        else{
            return mapper.selectList(new QueryWrapper<Paper>().eq("paper_subject",subject));
        }
    }

    public void save(Paper paper){
        mapper.insert(paper);
    }

    public void update(Paper paper){
        mapper.update(paper,new UpdateWrapper<Paper>());
    }

    public void delete(Integer id){
        mapper.deleteById(id);
    }
}
